import { Component,Injector } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { BasePage } from "../basePage";
import { PIC_URL } from '../../providers/Config';

/**
 * Generated class for the PicturelibPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-picturelib',
  templateUrl: 'picturelib.html',
})
export class PicturelibPage extends BasePage {

  piclist=[
    {'picimg':'','uploadpic':'','isshow':false},
    {'picimg':'','uploadpic':'','isshow':false},
    {'picimg':'','uploadpic':'','isshow':false},
    {'picimg':'','uploadpic':'','isshow':false},
    {'picimg':'','uploadpic':'','isshow':false},
    {'picimg':'','uploadpic':'','isshow':false},
  ];

  //选中图片的pic地址和index对象索引
  selectpic={"pic":"","index":0,"uploadpic":""};

  constructor(injector: Injector) {
    super(injector);    
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad PicturelibPage');
    this.piclistfun();
  }

  /**获取图片地址*/
  piclistfun(){
    for(let i=0;i<this.piclist.length;i++){
      this.piclist[i]["picimg"]=PIC_URL+'Uploads/default_avator/default_'+i+'.jpg';
      this.piclist[i]["uploadpic"]='Uploads/default_avator/default_'+i+'.jpg';
      this.piclist[i]['isshow']=false;
    }
    console.log(this.piclist);
  }

  /***选择图片 */
  selectpicCLI(i){
    for(let j=0;j<this.piclist.length;j++){
      if(i == j){
        this.selectpic.pic=this.piclist[j]["picimg"];
        this.selectpic.uploadpic=this.piclist[j]['uploadpic'];
        this.selectpic.index=i;
        this.piclist[j]['isshow']=true;
      }else{
        this.piclist[j]['isshow']=false;
      }
    }
  }

  /**完成头像的选择 */
  dismissokCLI(){
    this.viewCtrl.dismiss(this.selectpic);
  }

    /**返回上一个页面 */
  dismissCLI(){
    this.navCtrl.pop();
  }

}
